﻿using HemasHospitals.Controllers;
using HemasHospitals.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace HemasHospitals.Views
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class PatientReportScreen : Page
    {
        bool isPatientDetailsScreen = false;

        public PatientReportScreen()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            isPatientDetailsScreen = (bool)e.Parameter;
            patients_listview1.DataContext = PatientsData.GetReportsList1();
        }

        private void Logout_Click(object sender, RoutedEventArgs e)
        {
            Common.LogoutCommon(this.Frame);
        }

        private void Back_Click(object sender, RoutedEventArgs e)
        {
            if (isPatientDetailsScreen)
            {
                this.Frame.Navigate(typeof(PatientDetailsScreen), false);
            }
            else
            {
                this.Frame.Navigate(typeof(AppointmentHistory));
            }
        }
                
        private void PatientHistoryList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (patients_listview1.SelectedIndex == 0)
            {
                if (((PatientsReportsModel)patients_listview1.SelectedItem).ReportType=="X-Ray")
                {
                    //X-Ray
                    this.Frame.Navigate(typeof(PatientReportViewer), true);
                }

                if (((PatientsReportsModel)patients_listview1.SelectedItem).ReportType == "Blood")
                {
                    //Blood
                    this.Frame.Navigate(typeof(PatientReportStatisticsScreen), true);
                }
            }
            if (patients_listview1.SelectedIndex == 1)
            {
                if (((PatientsReportsModel)patients_listview1.SelectedItem).ReportType == "MRI")
                {
                    //MRI
                    this.Frame.Navigate(typeof(PatientReportViewer), false);
                }

                if (((PatientsReportsModel)patients_listview1.SelectedItem).ReportType == "Renal")
                {
                    //Renal
                    this.Frame.Navigate(typeof(PatientReportStatisticsScreen), false);
                }
            }
        }

        private void Rediology_Click(object sender, RoutedEventArgs e)
        {
            patients_listview1.DataContext = PatientsData.GetReportsList1();
        }

        private void Laborotary_Click(object sender, RoutedEventArgs e)
        {
            patients_listview1.DataContext = PatientsData.GetReportsList2();
        }
    }
}
